﻿using System;
using System.Collections.Generic;
using HK.Core.Common.Data;
using HK.Core.Common.Protocol;
using HK.Core.Common.Protocol.Data;
using HK.Core.Serializable.Protocol.Data;
using HK.Editor.GUIEx.Protocol.Data;
using HK.Editor.GUIEx.Protocol.TreeView.Data;
using HK.Editor.GUIEx.Protocol.Window;

namespace HK.Editor.Network.Download.Protocol.Data
{
    /// <summary>
    /// 下载验证状态
    /// </summary>
    [Flags]
    public enum DownloadVerifyState
    {
        /// <summary>
        /// 无
        /// </summary>
        None = 0x00000000,
        
        /// <summary>
        /// 下载中
        /// </summary>
        Downloading = 0x00000001,
        
        /// <summary>
        /// 已下载
        /// </summary>
        Downloaded = 0x00000002,
        
        /// <summary>
        /// 解压/解密中
        /// </summary>
        Decompressing = 0x00000004,
        
        /// <summary>
        /// 已解压/解密
        /// </summary>
        Decompressed = 0x00000008,
        
        /// <summary>
        /// 成功
        /// </summary>
        Succeeded = 0x00000010
    }
    
    /// <summary>
    /// 接口 : 下载验证Element
    /// </summary>
    public interface IDownloadVerifyElement : ITreeBranch, IListElement
    {
        /// <summary>
        /// 校验码 - Crc
        /// </summary>
        uint Crc { get; }
        
        /// <summary>
        /// 大小
        /// <para>* 单位 : Crc</para>
        /// </summary>
        long Size { get; }
        
        /// <summary>
        /// 下载进度
        /// </summary>
        float DownloadProgress { get; }
        
        /// <summary>
        /// 解压/解密进度
        /// </summary>
        float DecompressedProgress { get; }
        
        /// <summary>
        /// 下载地址
        /// </summary>
        string Url { get; }
        
#region State

        /// <summary>
        /// 状态
        /// </summary>
        int State { get; }
        
        /// <summary>
        /// 下载中
        /// </summary>
        bool Downloading { get; set; }
        
        /// <summary>
        /// 已下载
        /// </summary>
        bool Downloaded { get; set; }
        
        /// <summary>
        /// 解压/解密中
        /// </summary>
        bool Decompressing { get; set; }
        
        /// <summary>
        /// 已解压/解密
        /// </summary>
        bool Decompressed { get; set; }
        
        /// <summary>
        /// 成功
        /// </summary>
        bool Succeeded { get; set; }

#endregion
        
    }
    
    /// <summary>
    /// 接口 : 下载验证数据
    /// </summary>
    /// <typeparam name="TElement"></typeparam>
    public interface IDownloadVerifyData<TElement> : IWindowData, IListJsonData<TElement>
        where TElement : JsonData, IDownloadVerifyElement, IEquatable<TElement>
    {
        
        /// <summary>
        /// 日期
        /// <para>* 测试时频繁更新文件，此信息对检查是否是CDN缓存重要</para>
        /// </summary>
        string Date { get; }
        
        /// <summary>
        /// 上传者/创建者
        /// </summary>
        string Author { get; }
        
        /// <summary>
        /// 补丁包版本
        /// </summary>
        ISAssetVersion PathVer { get; }
        
        /// <summary>
        /// 母包版本
        /// </summary>
        ISAssetVersion OriginVer { get; }
        
        /// <summary>
        /// 描述文件版本号
        /// </summary>
        byte DescVer { get; }
        
        /// <summary>
        /// 总大小
        /// <para>* 单位 : Byte</para>
        /// </summary>
        long TotalSize { get; }
        
        /// <summary>
        /// 校验码 - Crc
        /// </summary>
        uint Crc { get; }
        
        /// <summary>
        /// 总个数
        /// <para>* 既:下载列表文件数</para>
        /// </summary>
        int TotalCount { get; }

        /// <summary>
        /// 下载验证对象列表
        /// </summary>
        List<TElement> Targets { get; }
        
        /// <summary>
        /// 下载目录
        /// </summary>
        string DownloadDir { get; }
        
    }
}
